let app = getApp();
Page({
  data: {
    countList:[{fix:[150,100], animation:null}, {fix:[160,230], animation:null},
      {fix:[140,170], animation:null}, {fix:[190,40], animation:null}, {fix:[190,280], animation:null}],
    shareList:[],
    getList:[],
    show:false,
    show2:false,
    userInfo:{nickname:'...'},
    shuidicount:0,
    onShow:false

  },
  onLoad: function (e) {
    let t = this;
    let customerId = wx.getStorageSync('customerId') || '';
    if(customerId){
      t.getInt(e);
    }else {
      app.page.onLoad(t, e);
      app.bus.onLoad(t);
    }
  },
  onShow(){
    this.data.onShow ? this.getInt({}) : this.setData({onShow:true});
  },
  getInt(ops){
    let t = this,userInfo=wx.getStorageSync('appUserInfo');
    t.setData({userInfo});
    app.request({
      url:getApp().api.siteinfo.apiroot+'shuidi/tasklist',
      data:{
        storeId:app.api.siteinfo.acid,
        share_type:ops.share_type || '',
        ori_token:ops.ori_token || '',
      },
      success(e){
        t.setData({shuidicount:e.shuidicount, getList:e.data})

        // 从转发卡片进入，且需要打开webview
        // share_type=6&ori_token=08gmcwWlTT9PtCilS_5ApgLPYgJIexG7&title=123&img=456
        ops.share_type > 3 && ops.share_type < 7  && wx.navigateTo({
          url:app.querystring(getApp().api.siteinfo.apiroot+'jsp/shuidi/url.jsp?type='+ops.share_type)+'&title='+ops.title+'&img='+ops.img
        })
      }
    });
    app.request({
      url:getApp().api.siteinfo.apiroot+'shuidi/paihang',
      data:{storeId:app.api.siteinfo.acid},
      success(e){t.setData({shareList:e.data})}
    });
  },
  conutClick(e) {
    let t=this,d = t.data,
        idx = e.currentTarget.dataset.idx,
        item = e.currentTarget.dataset.item,
        count = d.countList[idx];
    let animation = wx.createAnimation({duration:1000});
    animation.translate(160-count.fix[1],250-count.fix[0]).opacity(0).step();
    count.animation = animation;
    this.setData({countList:d.countList});

    app.request({
      url:getApp().api.siteinfo.apiroot+'shuidi/getshuidi',
      data:{storeId:app.api.siteinfo.acid, reward:item.reward, type:item.type, status:1},
      success(e){
        t.setData({shuidicount:e.shuidicount});
      }
    });

  },
  setShow(){
    this.setData({show:!this.data.show});
  },
  setShow2(){
    this.setData({show2:!this.data.show2});
  },
  goodsPage(){
    wx.navigateTo({url:'/activePages/trees/goods/goods?c='+this.data.shuidicount})
  },
  openUrl(e){
    // 打开webview
    let t=this,d = t.data, item = e.currentTarget.dataset.item;
    item.status === 2 && item.share === 1 && wx.navigateTo({
      url:app.querystring(getApp().api.siteinfo.apiroot+'jsp/shuidi/url.jsp?type='+item.type)+'&title='+item.share_title+'&img='+item.share_img
    })
  },
  openUrl2(){
    wx.navigateTo({
      url:app.querystring(getApp().api.siteinfo.apiroot+'jsp/shuidi/caution.jsp')
    })
  },
  onShareAppMessage(e){
    var item = this.data.getList[0];
    console.log(e)
    if(e.from === 'button'){
      // 按钮  // 右上角 menu
      item = e.target.dataset.item
    }
    return {
      path: '/activePages/trees/home/home?share_type=7&title='+item.share_title+'&img='+item.share_img+'&ori_token='+wx.getStorageSync('ACCESS_TOKEN'),
      title: decodeURIComponent(item.share_title),
      imageUrl: item.share_img
    }
  }
});